package com.example.wangshuo.zyfypt_205ws.model;

import com.example.wangshuo.zyfypt_205ws.iface.RegisterListener;
import com.example.wangshuo.zyfypt_205ws.iface.Registeriface;
import com.example.wangshuo.zyfypt_205ws.service.RegisterService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.scalars.ScalarsConverterFactory;

/**
 * Created by wangshuo on 2017/5/1.
 */

public class RegisterModel implements Registeriface {
    private Retrofit retrofit;
    private String BASEURL="http://amicool.neusoft.edu.cn/";

    public RegisterModel(){
        //实例化retrofit
        retrofit=new Retrofit.Builder().baseUrl(BASEURL).addConverterFactory(ScalarsConverterFactory.create()).build();

    }
    @Override
    public void getregtList(String username, String password, String tel, final RegisterListener listener) {
        RegisterService registerService=retrofit.create(RegisterService.class);
        Call<String> call=registerService.reg(username,password,tel);
        call.enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
               listener.onResponse(response.body());
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {
                listener.onFail(t.toString());

            }
        });


    }
}
